package com.bysj.service.impl;

import java.util.ArrayList;

import com.bysj.dao.UserDao;
import com.bysj.dao.impl.UserDaoImpl;
import com.bysj.entity.News;
import com.bysj.entity.User;
import com.bysj.service.UserService;

public class UserServiceImpl implements UserService{
	private UserDao ud=new UserDaoImpl();
	@Override
	public void addUser(User user) {
		String sql="insert into user(name,address,email,passwd,tel,sex,birthday) values(?,?,?,?,?,?,?)";
		ud.addUser(sql,user);
	}

	@Override
	public void updateUser(User user) {
		String sql="update user set name=?,address=?,birthday=?,tel=?,sex=?,nation=?,education=?,describeself=?,school=? where id=?";
		ud.updateUser(sql,user);
	}

	@Override
	public void delUser(User user) {
		String sql="delete from User where id=?";
		ud.delUser(sql,user);
	}

	@Override
	public User queryUser(User user) {
		String sql="select id,name,address,birthday,email,tel,pic,sex,nation,education,describeself,school,passwd from user where id=? ";
		return ud.queryUser(sql,user);
	}

	@Override
	public ArrayList<User> queryAllUser() {
		String sql="select id,name,address,birthday,email,tel,pic,sex,nation,education,describeself,school,passwd from user";
		return ud.queryAllUser(sql);
	}

	@Override
	public int accountAllUser() {
		String sql="select count(*) from user";
		return ud.CountAllUser(sql);
	}

	@Override
	public ArrayList<User> fenyeQuery(int page, int rows) {
		String sql="select id,name,address,birthday,email,tel,pic,sex,nation,education,describeself,school,passwd from user limit ?,?";
		return ud.FenyyeQuery(sql, page, rows);
	}

	@Override
	public boolean checkUserLogin(User u) {
		String sql="select id,name,address,birthday,email,tel,pic,sex,nation,education,describeself,school,passwd from user where email= ? and passwd= ? ";
		return ud.checkUserLogin(sql,u);
	}

	@Override
	public User queryUserByemailAndpasswd(User u) {
		String sql="select id,name,address,birthday,email,tel,pic,sex,nation,education,describeself,school,passwd from user where email= ? and passwd= ? ";
		return ud.queryUserByemailAndpasswd(sql,u);
	}

	@Override
	public boolean checkRegEmail(User user) {
		String sql="select email from user";
		return ud.checkRegEmail(sql,user);
	}

	@Override
	public User queryUserByEmail(User user) {
		String sql="select id,name,address,birthday,email,tel,pic,sex,nation,education,describeself,school,passwd from user where email=?";
		return ud.queryUserByemail(sql, user);
	}

	@Override
	public void updateuserPic(User user) {
		String sql="update user set pic=? where id=?";
		ud.updateUserPic(sql,user);
		
	}
	
	@Override
	public int CountUserByName(User user) {
		String sql="select count(*) from user where name like'%"+user.getName()+"%'";
		return ud.CountAllUser(sql);
	}

	@Override
	public int CountUserByBirthday(User user) {
		String sql="select count(*) from user where birthday like'%"+user.getBirthday()+"%'";
		return ud.CountAllUser(sql);
	}

	@Override
	public int CountUserByEmail(User user) {
		String sql="select count(*) from user where email like'%"+user.getEmail()+"%'";
		return ud.CountAllUser(sql);
	}

	@Override
	public int CountUserById(User user) {
		String sql="select count(*) from user where id like'%"+user.getId()+"%'";
		return ud.CountAllUser(sql);
	}

	@Override
	public int CountUserByTel(User user) {
		String sql="select count(*) from user where tel like'%"+user.getTel()+"%'";
		return ud.CountAllUser(sql);
	}

	@Override
	public int CountUserBySchool(User user) {
		String sql="select count(*) from user where school like'%"+user.getSchool()+"%'";
		return ud.CountAllUser(sql);
	}

	@Override
	public ArrayList<User> FenyeQueryById(int nowPage, int pageRowNum, User user) {
		String sql="select id,name,address,birthday,email,"
				+ "tel,pic,sex,nation,education,describeself,school,passwd from "
				+ "user where id like '%"+user.getId()+"%' "
				+ "limit ?,?";
		return ud.FenyyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<User> FenyeQueryByName(int nowPage, int pageRowNum,
			User user) {
		String sql="select id,name,address,birthday,email,"
				+ "tel,pic,sex,nation,education,describeself,school,passwd from "
				+ "user where name like '%"+user.getName()+"%' "
				+ "limit ?,?";
		return ud.FenyyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<User> FenyeQueryByTime(int nowPage, int pageRowNum,
			User user) {
		String sql="select id,name,address,birthday,email,"
				+ "tel,pic,sex,nation,education,describeself,school,passwd from "
				+ "user where birthday like '%"+user.getBirthday()+"%' "
				+ "limit ?,?";
		return ud.FenyyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<User> FenyeQueryByEmail(int nowPage, int pageRowNum,
			User user) {
		String sql="select id,name,address,birthday,email,"
				+ "tel,pic,sex,nation,education,describeself,school,passwd from "
				+ "user where email like '%"+user.getEmail()+"%' "
				+ "limit ?,?";
		return ud.FenyyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<User> FenyeQueryByTel(int nowPage, int pageRowNum,
			User user) {
		String sql="select id,name,address,birthday,email,"
				+ "tel,pic,sex,nation,education,describeself,school,passwd from "
				+ "user where tel like '%"+user.getTel()+"%' "
				+ "limit ?,?";
		return ud.FenyyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<User> FenyeQueryBySchool(int nowPage, int pageRowNum,
			User user) {
		String sql="select id,name,address,birthday,email,"
				+ "tel,pic,sex,nation,education,describeself,school,passwd from "
				+ "user where school like '%"+user.getSchool()+"%' "
				+ "limit ?,?";
		return ud.FenyyeQuery(sql, nowPage, pageRowNum);
	}
}
